/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.command;

import java.util.ArrayList;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.commons.controller.Controller;
import br.ufmg.dees.insane.model.geo.GCubicCurve;
import br.ufmg.dees.insane.model.geo.GCurve;
import br.ufmg.dees.insane.model.geo.GLine;
import br.ufmg.dees.insane.model.geo.GPoint;
import br.ufmg.dees.insane.model.geo.GQuadCurve;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;
import br.ufmg.dees.insane.ui.rich.full.controller.RegionController;

/**
 *
 * @author Pitangueira, Roque & Brugiolo, Marco & Fonseca, Flavio
 * @version 0.0.1 Beta
 */
public class AddFrameCommand implements Command, Cloneable {
    
    private InsaneInternalInterface parent;
    private Controller controller;
    private GCurve cv;
	
//*****************************************************************************
	
    /** Creates new AddFrameCommand */
    public AddFrameCommand(InsaneInternalInterface parent) {
		this.parent = (InsaneInternalInterface)parent;
		controller = this.parent.getController();
	}
	
//*****************************************************************************
	
    public void execute() {
		int count = 0;
		String message;
		ArrayList primit = controller.getSelection();
		if ( primit.size() > 0 ) {
			
			Object obj = primit.get(0);
			if (obj instanceof GPoint) {
				message = "A point can't be a frame element.";
			}
			if (obj instanceof GLine) {
				GLine line = (GLine)obj;
				line.setIsFrame(true);
				line.setColor(((RegionController)controller).getLineColor());
				count++;
			}
			if (obj instanceof GQuadCurve) {
				GQuadCurve quad = (GQuadCurve)obj;
				quad.setIsFrame(true);
				quad.setColor(((RegionController)controller).getLineColor());
				count++;
			}
			if (obj instanceof GCubicCurve) {
				GCubicCurve cubic = (GCubicCurve)obj;
				cubic.setIsFrame(true);
				cubic.setColor(((RegionController)controller).getLineColor());
				count++;
			}
			message = String.valueOf(count) + " primitives were set as frame elements.";
			parent.getController().add(cv);
			parent.getDrawing().repaint();
			
		}else{
			message = "Select primitives";
		}
		
		parent.addOutputText(message);
		controller.unSelectAll();
	}
	
//*****************************************************************************
	
	/** Impossible to undo - Not implemented */
	public void undo() {}
	
//*****************************************************************************
	
	/** Impossible to redo - Not implemented */
	public void redo() {}
	
//*****************************************************************************
}

